package com.amado.course37CharStream;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.Writer;
/**
 * 字符流，每次读取一行
 * @author Administrator
 *
 */
public class S04LineNumberReaderTest {
	public static void main(String[] args) throws IOException {
		String file = "D:\\test5.txt";
		// 写字符换转成字节流
//		FileOutputStream outputStream = new FileOutputStream(file);
//		FileInputStream inputStream = new FileInputStream(file);
//		Writer writer = new OutputStreamWriter(outputStream, charset);
		Writer writer = new FileWriter(file);
		try {
			writer.write("come 北京\n");
			writer.write("床前明月光，\n疑是地上霜，\n举头望明月，\n低头思故乡");
		} finally {
			writer.close();
		} // 读取字节转换成字符
//		Reader reader = new InputStreamReader(inputStream, charset);
		LineNumberReader reader = new LineNumberReader(new FileReader(file));
		StringBuffer buffer = new StringBuffer();
		try {
			String value= null;
			//每次读一行
			while ((value = reader.readLine())!=null) {
				System.out.println(value);
			}
		} finally {
			reader.close();
		}
		System.out.println(buffer);
	}
}
